package zhzzofbl;


import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import zhzz.AllIllnessOfZH;
import zhzz.SingleDataofzhzz;
import bingliandshuju.SingleDataofAll;

import com.example.animaldoctor03.JBXQ;
import com.example.animaldoctor03.R;
import com.example.animaldoctor03.ZhengDuanFF;

import commonClass.ADAQueryClinicalSymptomsKeyByDiseaseIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.ClinicalSymptomsKey;
import Modle.disease.Symptoms;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class bi4ofzh extends Activity{

	
	private String nameofBL4 = "";
	private String GLofBL4 ;
	private TextView  textofBL4= null ;
	private ListView listviewofbingli4 = null;
	private Button buttonofbingli4toJBXQ = null , buttonofbingli4forallchoice = null  ;
	private Button  buttonofbingli4toagain = null , buttonofBL4F =null;

	
	private List<Object> listofBL4getinformation = new ArrayList<Object>();
	private List<Object> listofbi4ofzhgetbasic = new ArrayList<Object>();
	private String animalIDofBL4 = "";
	private ArrayList<Object>resultListofBL4 = null;
	
	private  void initElemofBL4 (){
setContentView(R.layout.bingli4);

		buttonofBL4F = (Button)findViewById(R.id.buttonofBLF4);
		textofBL4 = (TextView)findViewById(R.id.textviewofbingli4);
		listviewofbingli4 = (ListView)findViewById(R.id.listofbingli4);
		buttonofbingli4forallchoice = (Button)findViewById(R.id.buttonofbingli44);
		buttonofbingli4toJBXQ = (Button)findViewById(R.id.buttonofbingli41);
		buttonofbingli4toagain = (Button)findViewById(R.id.buttonofbingli42);
		

		buttonofbingli4toJBXQ.setOnClickListener(new listenetofbingli4toJBXQ());
		buttonofbingli4toagain.setOnClickListener(new listenerofbingli4toagain());
		buttonofBL4F.setOnClickListener(new listenerofBL4F());
	}
private void getInformationofBL4 (){
		
		SingleDataofzhzz singleDataofbi4ofzh = SingleDataofzhzz.getInstance();
		listofbi4ofzhgetbasic = singleDataofbi4ofzh.getListinformation();
	
		SingleDataofAll singleDataofBL4 = SingleDataofAll.getInstance();
		
		listofBL4getinformation = singleDataofBL4.getListinformation();
	}

private void getInformationfromupofBL4(){
	Intent intentofBL4 = getIntent();
	Bundle bundleofBL4 = intentofBL4.getExtras();
	ClinicalSymptomsKey CofBL4 = (ClinicalSymptomsKey) bundleofBL4.getSerializable("shuju");
	animalIDofBL4 = CofBL4.getDiseaseID();
	nameofBL4 = CofBL4.getDiseaseName();
	DecimalFormat formatofBL4 = new DecimalFormat("#.0000");
	GLofBL4 =formatofBL4.format( CofBL4.getDiseaseProbability()) ;
	Message msgofBL4 = new Message();
	msgofBL4.what = 1;
	handleofBL4.sendMessage(msgofBL4);
}
private ArrayList<Object> assemblyofBL4() {

	getInformationfromupofBL4();
	ArrayList<Object> list = new ArrayList<Object>();

	list.add(animalIDofBL4);
	// Integer i = new Integer(10);
	// list.add(i);

	return list;
}	
private void bindingofBL4(final ArrayList<Object> list){
	try{
	getInformationofBL4();
	if(list.size() > 0){
		Log.v("22222", "bushikongzhi");
	}
	List<String> listofoldIdsofBL4 = new ArrayList<String>();
	for(int j = 0 ; j < listofbi4ofzhgetbasic.size() ; j++){
		Symptoms ctextofBL4 = (Symptoms) listofbi4ofzhgetbasic.get(j);
		listofoldIdsofBL4.add(ctextofBL4.getSymptomsID());
		
	}
	for(int i = 0 ; i < listofBL4getinformation.size(); i ++ ){
		
		Symptoms ctextofBL4 = (Symptoms) listofBL4getinformation.get(i);
		listofoldIdsofBL4.add(ctextofBL4.getSymptomsID());
		
	}
	List<Object> listofZZhuanofBL4 = new ArrayList<Object>();
	
	List<Object> listofBL4QC = new ArrayList<Object>();
	
	for(int j = 0 ; j < list.size() ; j ++){
		
		ClinicalSymptomsKey cetext1ofBL4 = (ClinicalSymptomsKey) list.get(j);
		String sofctext1ofBL4 = cetext1ofBL4.getClinicalSymptomsKeyID();
		for( String s : listofoldIdsofBL4){
			if(sofctext1ofBL4.equals(s)){
			
				listofBL4QC.add(cetext1ofBL4);
		}
		
	}
	}

		
	for(int i = 0 ; i < list.size(); i++ ){
		

		int jishuofBL4 = 0;
		ClinicalSymptomsKey ctext2ofBL4 = (ClinicalSymptomsKey) list.get(i);
		String sofctext2ofBL4 = ctext2ofBL4.getClinicalSymptomsKeyID();
		for(String s : listofoldIdsofBL4){
			if(!sofctext2ofBL4.equals(s)){
				jishuofBL4 ++;
				
			}
			if(jishuofBL4 == listofoldIdsofBL4.size()){
				listofZZhuanofBL4.add(ctext2ofBL4);
			}
			
		}
	}
	
		
		String[] resultofBL4 = new String[listofZZhuanofBL4.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < listofZZhuanofBL4.size(); i++) {
			
			
			//haiyouwenti
			resultofBL4[i] =( (ClinicalSymptomsKey)listofZZhuanofBL4.get(i)).getClinicalSymptomsKey() ;
		}
		ArrayAdapter<String> arrayAdapterofBL4 = new  ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice ,resultofBL4 );
		listviewofbingli4.setAdapter(arrayAdapterofBL4);
		buttonofbingli4forallchoice.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				 ArrayList<Object> listofnextofBL4 = new ArrayList <Object>();
				 List<String> listofb4ofid = new ArrayList<String>();
					for(long ids :listviewofbingli4.getCheckItemIds() ){
						
					int i = (int) ids;
						
						listofnextofBL4.add((ClinicalSymptomsKey)list.get(i));
						listofb4ofid.add(((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKeyID());
						//System.out.println("#################" + ids);
					}
					
					//把数据储存好
					SingleDataofAll singleDataofAllofBL4 = SingleDataofAll.getInstance();
					singleDataofAllofBL4.setListinformation(listofnextofBL4);
					singleDataofAllofBL4.setidinformation(listofb4ofid);
					List<String> listofb4ofzh = new ArrayList<String>();
					for(int e = 0 ; e < listofnextofBL4.size() ; e++){
						listofb4ofzh.add(((ClinicalSymptomsKey)listofnextofBL4.get(e)).getClinicalSymptomsKey());
						
					}
					singleDataofAllofBL4.setstringinformatin(listofb4ofzh);
					try{
						Intent intentofbingli3toallchoice = new Intent (bi4ofzh.this ,Choiceofzh.class );
						startActivity(intentofbingli3toallchoice);
						finish();
						}catch(RuntimeException e){
							android.app.AlertDialog.Builder builderofBL4oftoYXZZ = new AlertDialog.Builder(bi4ofzh.this);
							builderofBL4oftoYXZZ.setMessage("该功能不能使用,请重试或者使用其他功能");
							builderofBL4oftoYXZZ.create().show();
						}
			}
		});
	}catch(NullPointerException e){
		android.app.AlertDialog.Builder builderofBL4 = new AlertDialog.Builder(bi4ofzh.this);
		builderofBL4.setMessage("无数据 , 请用其他功能");
		builderofBL4.create().show();
	}
	}
@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		initElemofBL4();
		ArrayList<Object> parasListofBL4 = assemblyofBL4();
		
		final ArrayList<Object> resultListTofBL4 = null;
		
		ADAQueryClinicalSymptomsKeyByDiseaseIDAction iActionofBL4 = new ADAQueryClinicalSymptomsKeyByDiseaseIDAction();
		FunctionDispatcher functionDispacherofBL4 = new FunctionDispatcher();
		
		functionDispacherofBL4.exceute(RemoteActionsName.QueryClinicalSymptomsKeyByDiseaseIDAction, parasListofBL4, iActionofBL4, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				try{
				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				bi4ofzh.this.resultListofBL4 = resultList;
				bindingofBL4(resultListofBL4);
				}catch(NullPointerException e){
					android.app.AlertDialog.Builder builderofBL4off = new AlertDialog.Builder(bi4ofzh.this);
					builderofBL4off.setMessage("返回数据为空 ,请用其他功能");
					builderofBL4off.create().show();
				}
			}
		},this);

		
		

		
	}
class listenerofBL4F implements OnClickListener{

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		try{
		Intent intentofBL4F = new Intent(bi4ofzh.this , ZhengDuanFF.class);
		startActivity(intentofBL4F);
		finish();
		}catch(RuntimeException e){
			android.app.AlertDialog.Builder builderofBL4ofF = new AlertDialog.Builder(bi4ofzh.this);
			builderofBL4ofF.setMessage("该功能不能使用,请重试或者使用其他功能");
			builderofBL4ofF.create().show();
		}

		
	}
	
}

	
	class listenerofbingli4toagain implements   OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
			try{
/*			List<Object> listofagainofBL4 = new ArrayList<Object>();
			SingleDataofAll singDataofallagainofBL4 = SingleDataofAll.getInstance();
			listofagainofBL4 = singDataofallagainofBL4.getListinformation();
			Bundle bundleofagainofBL4 = new Bundle();
			bundleofagainofBL4.putSerializable("shuju", (Serializable) listofagainofBL4);*/
			Intent intentofbingli4toagain = new Intent (bi4ofzh.this , AllIllnessOfZH.class);
			/*intentofbingli4toagain.putExtras(bundleofagainofBL4);*/
			startActivity(intentofbingli4toagain);
			finish();
			}catch(RuntimeException e){
				android.app.AlertDialog.Builder builderofBL4oftoA = new AlertDialog.Builder(bi4ofzh.this);
				builderofBL4oftoA.setMessage("该功能不能使用,请重试或者使用其他功能");
				builderofBL4oftoA.create().show();
			}
		}

	}
	
	class listenetofbingli4toJBXQ implements OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			try{

			Bundle bundleofBL4 = new Bundle();
			bundleofBL4.putString("shuju", animalIDofBL4);
			Intent intentofbingli4toJBXQ = new Intent (bi4ofzh.this , JBXQ.class);
			intentofbingli4toJBXQ.putExtras(bundleofBL4);
			startActivity(intentofbingli4toJBXQ);
			finish();
			}catch(RuntimeException e){
				android.app.AlertDialog.Builder builderofBL4oftoJBXQ= new AlertDialog.Builder(bi4ofzh.this);
				builderofBL4oftoJBXQ.setMessage("该功能不能使用,请重试或者使用其他功能");
				builderofBL4oftoJBXQ.create().show();
			}
			
		}
		
	}
	public Handler handleofBL4 = new Handler() {
		
		public void  handleMessage(Message msg) {
			
			if(msg.what == 1){
				textofBL4.setText("病名：" + nameofBL4 + " " + "概率：" + "0" + GLofBL4);
			}
		}
	};
	
}

